package org.zyj.io.example.case7;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.zyj.io.example.codec.protobuf.MyData;

/**
 * 描述
 *
 * @author zhouyijin
 * @date 2022-01-14 14:48:54
 */
class ProtobufMultiMsgServerHandler extends SimpleChannelInboundHandler<MyData.MyMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyData.MyMessage msg) throws Exception {
        switch (msg.getDataType()) {
            case TeacherType -> System.out.println("老师信息为: " + msg.getTeacher().getName());
            case StudentType -> System.out.println("学生信息为: " + msg.getStudent().getName());
        }
    }

    //处理异常, 一般情况是关闭通道
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}
